<template>
  <div class="xhs-container">
    <!-- 顶部导航栏 -->
    <el-header class="xhs-header">
      <div class="header-content">
        <div class="logo">小红书</div>
        <el-input placeholder="搜索感兴趣的内容" class="search-input" prefix-icon="Search" />
        <div class="nav-icons">
          <el-icon class="nav-icon">
            <HomeFilled />
          </el-icon>
          <el-icon class="nav-icon">
            <Bell />
          </el-icon>
          <el-icon class="nav-icon">
            <ChatDotRound />
          </el-icon>
          <el-avatar
            :size="30"
            src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
          />
        </div>
      </div>
    </el-header>
    <!-- 主要内容区域 -->
    <el-container class="main-container">
      <!-- 侧边导航 -->
      <el-aside width="200px" class="sidebar">
        <el-menu default-active="1" class="sidebar-menu" :collapse="false">
          <el-menu-item index="1">
            <el-icon>
              <House />
            </el-icon>
            <span>首页</span></el-menu-item
          >
          <el-menu-item index="2">
            <el-icon>
              <Compass />
            </el-icon>
            <span>发现</span></el-menu-item
          >
          <el-menu-item index="3">
            <el-icon>
              <Star />
            </el-icon>
            <span>关注</span></el-menu-item
          >
          <el-menu-item index="4">
            <el-icon>
              <ShoppingBag />
            </el-icon>
            <span>商城</span></el-menu-item
          >
        </el-menu>
      </el-aside>
      <!-- 内容流 -->
      <el-main class="content-main">
        <!-- 发布按钮 -->
        <div class="publish-btn-container">
          <el-button type="danger" round class="publish-btn">
            <el-icon>
              <EditPen />
            </el-icon>
            发布笔记
          </el-button>
        </div>
        <!-- 笔记卡片列表 -->
        <div class="notes-container">
          <el-row :gutter="20">
            <el-col :span="8" v-for="note in notes" :key="note.id" class="note-col">
              <el-card class="note-card" shadow="hover">
                <div class="note-image"><img :src="note.image" alt="笔记封面" /></div>
                <div class="note-content">
                  <div class="author-info">
                    <el-avatar :size="30" :src="note.author.avatar" />
                    <span class="author-name">{{ note.author.name }}</span>
                  </div>
                  <p class="note-title">{{ note.title }}</p>
                  <div class="note-stats">
                    <span class="likes"
                      ><el-icon><StarFilled /></el-icon> {{ note.likes }}</span
                    >
                    <span class="comments"
                      ><el-icon><ChatLineSquare /></el-icon> {{ note.comments }}</span
                    >
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>
        <!-- 加载更多 -->
        <div class="load-more">
          <el-button @click="loadMore">加载更多</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>
<script setup>
import { onBeforeMount, ref } from 'vue'
// 引入axios库，用于发送HTTP请求
import axios from 'axios'
import {
  HomeFilled,
  Bell,
  ChatDotRound,
  House,
  Compass,
  Star,
  ShoppingBag,
  EditPen,
  StarFilled,
  ChatLineSquare,
} from '@element-plus/icons-vue'
// 模拟笔记数据
const notes = ref([])
// 加载更多功能
const loadMore = () => {
  // 模拟加载更多数据
  axios
    .get('/notes')
    .then((res) => {
      const newNotes = res.data
      notes.value = [...notes.value, ...newNotes]
    })
}

// 编写发生axios请求获取笔记数据的方法
function getNotes() {
  // 获取数据通常使用get请求，那么对应axios中的get方法
  axios
    .get('https://m1.apifoxmock.com/m1/2168624-537750-default/notes')
    // 通过then方法，处理获取到的响应，其中res是响应对象，我们可以直接从响应中获取数据
    .then((res) => {
      // 打印获取到的笔记数据
      console.log(res.data)
      // 将获取到的笔记数据赋值给notes
      notes.value = res.data
    })
}

// 调用生命周期中创建后的生命周期函数，调用getNotes方法
onBeforeMount(() => {
  getNotes()
})
</script>
<style scoped>
.xhs-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.xhs-header {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 0;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #ff6666;
  margin-right: 30px;
}

.search-input {
  flex: 1;
  max-width: 400px;
  margin-right: 30px;
}

.nav-icons {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-icon {
  font-size: 20px;
  cursor: pointer;
  color: #333;
}

.main-container {
  padding: 20px;
}

.sidebar {
  background-color: #fff;
  border-radius: 8px;
  padding: 10px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  height: fit-content;
}

.sidebar-menu {
  border: none;
}

.publish-btn-container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.publish-btn {
  padding: 12px 24px;
}

.notes-container {
  margin-bottom: 30px;
}

.note-col {
  margin-bottom: 20px;
}

.note-card {
  border-radius: 12px;
  overflow: hidden;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.note-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.note-image {
  width: 100%;
  height: 200px;
  overflow: hidden;
}

.note-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.note-content {
  padding: 15px;
}

.author-info {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.author-name {
  margin-left: 10px;
  font-weight: 500;
  font-size: 14px;
}

.note-title {
  font-size: 16px;
  margin-bottom: 15px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-stats {
  display: flex;
  gap: 15px;
  color: #999;
  font-size: 14px;
}

.note-stats .el-icon {
  margin-right: 4px;
}

.load-more {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>
